package org.act.xservices.engine.rt.utils;

import javax.xml.namespace.QName;

public class QNameUtil {
	
	public static String getPrefix(String qname) {
		int index = qname.indexOf(":");
		if(index != -1) {
			return qname.substring(0, index);
		}
		return "";
	}
	
	public static String getLocalName(String qname) {
		int index = qname.indexOf(":");
		if(index != -1) {
			return qname.substring(index+1);
		}
		return qname;
	}
	
	public static QName translate(Object qname) {
		if(qname != null) {
			if(qname instanceof QName){
				return (QName)qname;
			}else{
				org.eclipse.emf.ecore.xml.type.internal.QName qName = (org.eclipse.emf.ecore.xml.type.internal.QName)qname;
				String uri = qName.getNamespaceURI();
			    String localPart = qName.getLocalPart();
			    QName name = new QName(uri, localPart);
			    return name;
			}	
		}
		return null;
	}
}
